package com.icode.core.dto.house;

import com.icode.core.model.house.Agreement;
import com.icode.core.model.house.HouseInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: lb
 * Date: 15-11-23
 * Time: 下午2:50
 * To change this template use File | Settings | File Templates.
 */
public class AgreementDTO {

    private String guid;
    private HouseInfo houseInfo;
    private String content;
    private String houseInfoguid;
    private String houseName;

    public AgreementDTO() {

    }

    public AgreementDTO(HouseInfo houseInfo, String content, String houseInfoguid) {
        this.houseInfo = houseInfo;
        this.content = content;
        this.houseInfoguid = houseInfoguid;
    }

    public AgreementDTO(String guid, HouseInfo houseInfo, String content, String houseInfoguid) {
        this.guid = guid;
        this.houseInfo = houseInfo;
        this.content = content;
        this.houseInfoguid = houseInfoguid;
        this.houseName = houseInfo.baseInfo().houseName();
    }

    public static AgreementDTO toDTO(Agreement agreement) {
        String guid = agreement.guid();
        HouseInfo houseInfo = agreement.houseInfo();
        String content = agreement.content();
        String houseInfoguid = agreement.houseInfo().guid();
        return new AgreementDTO(guid, houseInfo, content, houseInfoguid);
    }

    public static Agreement toAgreement(AgreementDTO agreementDTO, HouseInfo houseInfo) {
        Agreement agreement = new Agreement(houseInfo, agreementDTO.getContent());
        return agreement;
    }

    public static List<AgreementDTO> toDTOs(List<Agreement> agreements) {
        List<AgreementDTO> agreementDTOs = new ArrayList<>();
        for (Agreement agreement : agreements) {
            AgreementDTO agreementDTO = toDTO(agreement);
            agreementDTOs.add(agreementDTO);
        }
        return agreementDTOs;
    }

    public String getGuid() {
        return guid;
    }

    public void setGuid(String guid) {
        this.guid = guid;
    }

    public HouseInfo getHouseInfo() {
        return houseInfo;
    }

    public void setHouseInfo(HouseInfo houseInfo) {
        this.houseInfo = houseInfo;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getHouseInfoguid() {
        return houseInfoguid;
    }

    public void setHouseInfoguid(String houseInfoguid) {
        this.houseInfoguid = houseInfoguid;
    }

    public String getHouseName() {
        return houseName;
    }

    public void setHouseName(String houseName) {
        this.houseName = houseName;
    }
}
